//  基于wxpage.js 优化其$redirect $route等route跳转函数 适应项目目录

const ROUTE_CACHE_KEY = 'a-route-page-from'

function handlePageArgs(name, query) {
  let s
  if (name.indexOf('?') > -1) {
    let urlArr = name.split('?')
    s = '/pages/' + urlArr[0] + '/index?' + urlArr[1]
  } else {
    s = '/pages/' + name + '/index'
    if (query) {
      s = '?' + query
    }
  }
  return s
}

function setRouteCache(context) {
  context.$cache.set(ROUTE_CACHE_KEY, context.$curPage().$pageName, 1000 * 60 * 60 * 3);
}

function getRouteCache(context) {
  return context.$cache.get(ROUTE_CACHE_KEY);
}

module.exports = {
  handlePageArgs,
  setRouteCache,
  getRouteCache,
}
